import { createStore } from 'vuex';

const SERVICE_TIME = 'serviceTime';
const ACTIVITY_INIT = 'activityInit';
const SENIOR_SET = 'seniorSet';

export default createStore({
  state: {
    serviceTime: JSON.parse(sessionStorage.getItem(SERVICE_TIME)) ?? null,
    initData: JSON.parse(sessionStorage.getItem(ACTIVITY_INIT)) ?? null,
    seniorSet: JSON.parse(sessionStorage.getItem(SENIOR_SET)) ?? null,
  },
  mutations: {
    SET_SERVICE_TIME(state, serviceTime) {
      state.serviceTime = serviceTime;
      sessionStorage.setItem(SERVICE_TIME, JSON.stringify(serviceTime));
    },
    SET_INIT_DATA(state, initData) {
      state.initData = initData;
      sessionStorage.setItem(ACTIVITY_INIT, JSON.stringify(initData));
    },
    SET_SENIOR_SET(state, seniorSet) {
      state.seniorSet = seniorSet;
      sessionStorage.setItem(SENIOR_SET, JSON.stringify(seniorSet));
    },
  },
  actions: {
    setServiceTime({ commit }, serviceTime) {
      commit('SET_SERVICE_TIME', serviceTime);
    },
    setInitData({ commit }, initData) {
      commit('SET_INIT_DATA', initData);
    },
    setSeniorSet({ commit }, seniorSet) {
      commit('SET_SENIOR_SET', seniorSet);
    },
  },
});
